package com.hengyue.common.core.service;

import com.hengyue.common.core.entity.BaseEntity;
import com.hengyue.common.core.respository.BaseRepository;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.Set;


//@RequiredArgsConstructor
public abstract class BaseServiceImpl<T extends BaseEntity, R extends BaseRepository<T, ID>, ID> /*implements IBaseService<T, ID>*/ {

    //@PersistenceContext
    //private final EntityManager em;


  /*  @Autowired
    @SuppressWarnings("all")
    private  R repository;*/





   abstract public R getRepository();


    /*
    @Override
    public List<T> findAll() {
        return repository.findAll();
        //return getRepository().findAll();
    }

    @Override
    public Page<T> findAll(Pageable pageable) {
        return repository.findAll(pageable);
    }

    @Override
    public List<T> findAll(Sort sort) {
        return repository.findAll(sort);
    }

    @Override
    public List<T> findAll(Specification<T> spec) {
        return repository.findAll(spec);
    }

    @Override
    public Page<T> findAll(Specification<T> spec, Pageable pageable) {
        return repository.findAll(spec, pageable);
    }

    @Override
    public List<T> findAllById(Iterable<ID> ids) {
        return repository.findAllById(ids);
    }

    @Override
    public Optional<T> findById(ID id) {
        return repository.findById(id);
    }

    @Override
    public <S extends T> List<S> saveAll(Iterable<S> entities) {

        return repository.saveAll(entities);
    }

    @Override
    public <S extends T> List<S> saveAllAndFlush(Iterable<S> entities) {

        return repository.saveAll(entities);
    }

    @Override
    public void flush() {
        repository.flush();
        ;
    }

    @Override
    public <S extends T> S saveAndFlush(S entity) {
        return repository.saveAndFlush(entity);
    }

    @Override
    public <S extends T> S save(S entity) {
        return repository.save(entity);
    }

    @Override
    public void delete(T entity) {
        repository.delete(entity);
    }

    @Override
    public void deleteById(ID id) {
        repository.deleteById(id);
    }

    @Override
    public void deleteAll() {
        repository.deleteAll();
    }

    @Override
    public void deleteAll(Iterable<T> entities) {
        repository.deleteAll(entities);
    }

    @Override
    public void deleteAllByIdInBatch(Iterable<ID> ids) {
        repository.deleteAllByIdInBatch(ids);
    }

    @Override
    public boolean existsById(ID id) {
        return repository.existsById(id);
    }

    @Override
    public long count() {
        return repository.count();
    }*/
}
